holder<-summary(my.model,quantiles=c(0.025,0.05,0.5,0.95,0.975))

## Check convergence

my.judge.geweke<-geweke.diag(my.model[,grep("theta",colnames(my.model))])

## Now calculate measures of fit
xbar<-holder$statistics[grep("theta",names(holder$statistics[,1])),1]
alphabar<-holder$statistics[grep("alpha",names(holder$statistics[,1])),1]
betabar<-holder$statistics[grep("beta",names(holder$statistics[,1])),1]

predprob <- matrix(NA, ncol = ncol(votes), nrow = nrow(votes))
dimnames(predprob) <- dimnames(votes)
pred <- predprob
correct <- predprob

betabar<-cbind(betabar,alphabar) ## this is the way pscl does it
x1 <- cbind(xbar, -1)

mu <- tcrossprod(x1, betabar)
predprob <- pnorm(mu)
pred <- predprob >= 0.5
correct <- votes == pred
correct[is.na(votes)] <- NA

## percentage correct

overall.percent <- (sum(correct, 
            na.rm = T)/sum(!is.na(correct))) * 100 ## 88.5
yea.percent <- (sum(correct[votes == 
            1], na.rm = T)/sum(!is.na(correct[votes == 1]))) * 
            100 ## 96.0
nay.percent <- (sum(correct[votes == 0], na.rm = T)/sum(!is.na(correct[votes == 
            0]))) * 100 ## 62.8

## percentage correct by legislator

lp <- apply(correct, 1, pscl:::tally) * 100

## calculate null model percent correct
null.pred<-matrix(1,nrow=nrow(predprob),ncol=ncol(predprob))
null.correct <- votes==null.pred
null.percent=(sum(null.correct,na.rm=T)/sum(!is.na(null.correct)))*100 ## 72.9%

## calculate APRE

errors<-colSums(votes!=pred,na.rm=T)
min_vote<-function(x) {
	minority_outcome<-as.numeric(names(sort(table(na.omit(x)),decreasing=TRUE))[2])
	minority_outcome
}
minority_on_each_vote<-apply(votes,2,function(x)sum((x==min_vote(x)),na.rm=T))

pre<-(minority_on_each_vote-errors)/minority_on_each_vote
apre<-mean(pre,na.rm=T) ## 

## logLik
pijt_1<-log(predprob)
pijt_0<-log(1-predprob)

pijt_1<-pijt_1*(votes==1)
pijt_0<-pijt_0*(votes==0)

my.logLik<-sum(pijt_0,pijt_1,na.rm=T)

my.A<-length(which(!is.na(votes)))

GMP<-exp(my.logLik/my.A)
GMP

## Discriminating cases

my.discriminating<-(holder$quantiles[grep("beta",rownames(holder$quantiles)),"2.5%"]>0 | holder$quantiles[grep("beta",rownames(holder$quantiles)),"97.5%"]<0)
